home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Business ROM with ClearVue 12-94
/
Business ROM with ClearView v12-94.iso
/
tools
/
spredsht
/
we0127
/
we0127.txt
< prev
Wrap
Text File
|
1992-02-19
|
8KB
|
206 lines
======================================================================
Microsoft Product Support Services Application Note (Text File)
WE0127: Dates and Times
======================================================================
Revision Date: 2/92
No Disk Included
The following information applies to Microsoft Excel for Windows
version 3.0.
--------------------------------------------------------------------
| INFORMATION PROVIDED IN THIS DOCUMENT AND ANY SOFTWARE THAT MAY |
| ACCOMPANY THIS DOCUMENT (collectively referred to as an |
| Application Note) IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY |
| KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO |
| THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A |
| PARTICULAR PURPOSE. The user assumes the entire risk as to the |
| accuracy and the use of this Application Note. This Application |
| Note may be copied and distributed subject to the following |
| conditions: 1) All text must be copied without modification and |
| all pages must be included; 2) If software is included, all files |
| on the disk(s) must be copied without modification [the MS-DOS(R) |
| utility DISKCOPY is appropriate for this purpose]; 3) All |
| components of this Application Note must be distributed together; |
| and 4) This Application Note may not be distributed for profit. |
| |
| Copyright 1992 Microsoft Corporation. All Rights Reserved. |
| Microsoft, MS-DOS, and the Microsoft logo are registered |
| trademarks and Windows is a trademark of Microsoft Corporation. |
--------------------------------------------------------------------
General Information
-------------------
Microsoft Excel for Windows uses serial numbers to keep track of dates
and times. Using this serial number system, you can add, subtract, and
compare dates and times as you do any other number values. This date
and time system begins with the serial number 1.0, which represents
1/1/1900 0:00:00 (12:00:00 a.m.), and increases by 1.0 for every 24
elapsed hours, ending with the serial number 65380.99999, which
represents 12/31/2078 23:59:59 (11:59:59 p.m.). The integer portion of
the serial number represents the date, and the decimal portion
represents the time.
It is important to note that Microsoft Excel for Windows cannot
manipulate dates that extend beyond the range of 1/1/1900 through
12/31/2078. Using a date outside of this range will result in an
error.
Comparing Dates and Times
-------------------------
Because Excel uses serial numbers when calculating functions that
involve dates and times, you may get results that are different from
what you expect. For instance, the following function may return FALSE
even if today's date is 1/31/92:
=IF(NOW()=DATEVALUE("1/31/92"),TRUE,FALSE)
This function will return TRUE only when the current date and time are
1/31/92 and 12:00:00 a.m. This is because the NOW function returns the
serial number of the current date and time, which may not equal the
serial number of only the date, which is returned by the DATEVALUE
function. The correct formula for comparing today's date with another
date is:
=IF(TODAY()=DATEVALUE("1/31/92"),TRUE,FALSE)
Another workable formula is:
=IF(INT(NOW())=DATEVALUE("1/31/92"),TRUE,FALSE)
In the preceding formula, the INT function strips the decimal portion
of the serial number from the NOW function. Thus, the formula returns
TRUE.
Date Formulas
-------------
The following example shows how the various date functions can be
used:
--------------------------------------------------
| | A | B | C |
|--------------------------------------------------|
| 1 | DATE1 | DATE2 | DIFFERENCE |
|--------------------------------------------------|
| 2 | 12/20/1970 | 1/20/2000 | |
--------------------------------------------------
1. To find the number of days between two dates, subtract the earlier
date from the later date:
=B2-A1
2. To compute the number of days between the current date and the date
specified in cell B2, use:
=B2-TODAY()
3. To find the number of years, months, and days between two dates,
use:
=YEAR(B2)-YEAR(A2)-IF(OR(MONTH(B2)<MONTH(A2),
AND(MONTH(B2)=MONTH(A2),DAY(B2)<DAY(A2))),1,0)&"y"
&MOD(MONTH(B2)-MONTH(A2),12)-IF(DAY(B2)<DAY(A2),1,0)&"m"
&B2-DATE(YEAR(B2),MONTH(B2)-IF(DAY(B2)<DAY(A2),1,0),DAY(A2))&"d"
In the above formulas, lines 1 and 2 calculate the number of years
between the dates in cells A2 and B2. Line 3 calculates the number
of months between the dates in cells A2 and B2, ignoring years and
days. Line 4 calculates the number of days between the dates in
cells A2 and B2, ignoring years and months. The ampersand symbol
(&) concatenates the formulas together and labels the result with y,
m, and d. If you entered these formulas in cell C2 of our example,
29y0m21d would be the result.
4. To find the number of weekdays between two dates, use:
=B2-A2-INT((B2-A2)/7)*2-IF(WEEKDAY(B2)<WEEKDAY(A2),2,0)
If you entered this formula in cell C2 of the above example, 7581
would be the result.
5. To increase a date by a given number of years, months, and days,
use
=DATE(YEAR(A2)+y,MONTH(A2)+m,DAY(A2)+d)
where y, m, and d are the number of years, months, and days by
which you want to increase the date in cell A2.
6. To determine the total number of days in the month of a given date,
use:
=DAY(DATE(YEAR(A2),MONTH(A2)+1,0))
In our example, this formula would return 31.
7. To determine the total number of days in the year of a given date,
use:
=DATE(YEAR(A2)+1,1,0)-DATE(YEAR(A2),1,0)
In our example, this formula would return 365.
Time Formulas
-------------
The following example shows how the various time functions can be
used:
---------------------------------------------
| | A | B | C |
|---------------------------------------------|
| 1 | START | END | DIFFERENCE |
|---------------------------------------------|
| 2 | 6:30 AM | 7:15 PM | 12:45 |
|---------------------------------------------|
| 3 | 7:45 PM | 10:30 AM | 14:45 |
---------------------------------------------
1. To find the amount of elapsed time between two given times, simply
subtract the earlier time from the later:
=B2-A2
The result of this formula will be the serial number representing
the elapsed hours, minutes, and seconds. To change the serial
number to a more conventional format, select the cell, choose
Number from the Format menu, and then select one of the time
formats, such as h:mm.
2. If midnight falls between your starting and ending times, as in row
3 of the example, you must account for the 24-hour time difference
between the serial numbers, as in the following formula:
=MOD(B3-A3,1)
3. To add a series of hours and minutes where the total exceeds 24
hours, Excel will begin to count over again at 1. For example, if
you add cells C2 and C3 using a simple sum formula such as
=C2+C3
the result of this formula will be 3:30 if the cell was formatted
as h:mm, or 1.145833 if the cell was formatted as General. Neither
result returns the number of hours elapsed as desired. The
following formula multiplies the sum by 24, which accounts for this
"roll over" into a new day:
=24*(C2+C3)
This formula will return the correct answer of 27.5 hours.
More Information
----------------
For an index of all valid date and time functions, see the "Microsoft Excel
for Windows Function Reference," version 3.0, page xvi.